package com.example.onlinemonitoring.serviceImpl;
import com.example.onlinemonitoring.model.Appdevice;
import com.example.onlinemonitoring.model.Dlzllconfig;
import com.example.onlinemonitoring.model.Dlzllsensor;
import com.example.onlinemonitoring.model.Dlzlldssensor;
import com.example.onlinemonitoring.model.Dtssensor;
import com.example.onlinemonitoring.model.Oilconfig;
import com.example.onlinemonitoring.model.Oilsensor;
import com.example.onlinemonitoring.model.Dlzllhistory;

import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.example.onlinemonitoring.Util.tem.SensorAbstractBaseService;
import com.example.onlinemonitoring.service.DlzllsensorService;
import com.github.pagehelper.PageHelper;
import com.example.onlinemonitoring.model.common.chartres;
import com.example.onlinemonitoring.model.common.series;
import com.example.onlinemonitoring.Util.HexUtil;
import com.example.onlinemonitoring.dao.DlzllconfigMapper;
import com.example.onlinemonitoring.dao.DlzlldssensorMapper;
import java.util.*;

//import static com.example.onlinemonitoring.Util.tem.SensorAbstractBaseService.getValueType;

// import static com.example.onlinemonitoring.Util.tem.SensorAbstractBaseService.getValueType;
// import static com.example.onlinemonitoring.Util.tem.SensorAbstractBaseService.newTclass;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import tk.mybatis.mapper.entity.Example;
import com.example.onlinemonitoring.Util.ConditionDispose;
import com.example.onlinemonitoring.model.common.MyResult;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.example.onlinemonitoring.Util.CommPortManager;
import com.example.onlinemonitoring.Util.LanguageManager;

/**
* @description Dlzllsensor接口实现
* @author  generator
* @since  2023-11-08 13:56:29
*/
@Service("dlzllServiceImpl")
public class DlzllsensorServiceImpl extends SensorAbstractBaseService<Dlzllsensor, Dlzllhistory> implements DlzllsensorService {
    @Autowired
    DlzllconfigMapper dlzllconfigmapper;
    @Autowired
    DlzlldssensorMapper dlzlldsmapper;
    @Autowired
    LanguageManager languageManager;

    public float Calccurrent1(Dlzllsensor record)
    {
        float dcurrent=280;
        float ω= 2*3.14159f*50;
        float Rc=0, R1p=0, Xs2=0, Ys=0, Xp2=0, Yp=0;
        float Wd=0,c=0;
        float As=0;
        float λ1=0,λ11=0,λ12=0,Rs=0,gs=0,β1=0,λ0=0,m=0,Δ1=0,X=0;
        float λ2=0,Ra=0;
        float T1=0;
        float T2=0;
        float T3=0;
        float T4=0,u=0;
        float θc=90,θa = 25,θs=20,θc1=41;
        float calsum=0;
        float ts=0,Ds=0;
        Dlzllconfig dlcf = new Dlzllconfig();
        //oc.setStationid(record.getStationid());
        //oc.setDevicegroup(record.getDevicegroup());
        //oc.setDeviceaddr(record.getDeviceaddr());
        Example example = new Example(Dlzllconfig.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stationid", record.getStationid());
        criteria.andEqualTo("devicegroup", record.getDevicegroup());
        criteria.andEqualTo("deviceaddr", record.getDeviceaddr());
        criteria.andEqualTo("pointaddr", record.getPointaddr());
        dlcf = dlzllconfigmapper.selectOneByExample(example);

        float Cddter = dlcf.getCddter();
        c = dlcf.getInsulε()/18/((float)Math.log(dlcf.getInsuldter())-(float)Math.log(Cddter));
        Wd = ω*c*dlcf.getVollevel()*dlcf.getVollevel()*dlcf.getInsultanδ()*1000000*0.000000001f;
        //Wd = 0.9f;
       
        R1p = dlcf.getCd20dcr()*(1+dlcf.getCdrtempcoef()*(90-20));
        Xs2 = 8*3.14159f*50/R1p*0.0000001f*dlcf.getCdks()*1000;
        Ys = Xs2*Xs2/(192+0.8f*Xs2*Xs2);
        Xp2 = 8*3.14159f*50/R1p*dlcf.getCdkp()*0.0000001f;
        Yp = Xp2*Xp2/(192+0.8f*Xp2*Xp2)*(Cddter/dlcf.getCdaxis())*(Cddter/dlcf.getCdaxis())*(0.312f*(Cddter/dlcf.getCdaxis())*(Cddter/dlcf.getCdaxis())+1.18f/(Xp2*Xp2/(192+0.8f*Xp2*Xp2))+0.27f);
        if(dlcf.getCdcorenum()==1)
        Yp=0;
        Rc = R1p*(1+Ys+Yp)*0.001f;
        //Rc =0.0108f;
        ts = dlcf.getMetalthick();
        Ds = dlcf.getMetalinnerd();
       // As = (3.14159f*(Ds+ts)/2*(Ds+ts)/2)*0.000001f;
        As = 3.14159f*Ds*ts*0.000001f;
        Rs = dlcf.getMetalres()/As*(1+dlcf.getCdrtempcoef()*(record.getLastcdtemperature()*0.8f - 20));

        β1 = (float)Math.sqrt(4*3.14159f*ω/10000000/dlcf.getMetalres());//2*3.14159f*(2*50/(dlcf.getMetalres()*0.1f);(dlcf.getMetalinnerd()+dlcf.getMetalinnerd()+dlcf.getMetalthick())/2
        gs = 1+(float)Math.pow((ts/(Ds+ts)),1.74f)*(β1*(Ds+ts)*0.001f-1.6f);
        m = ω/(Rc*dlcf.getCdaxis())*0.0000001f;
        λ0 = 6*(m*m)/(1+m*m)*((Ds+ts)/2/dlcf.getCdaxis())*((Ds+ts)/2/dlcf.getCdaxis());
        Δ1 = 0.86f*(float)Math.pow(m,3.08f)*(float)Math.pow((Ds+ts)/2/dlcf.getCdaxis(),1.4f*m+0.7f);
        λ12 =Rs/Rc*(gs*λ0*(1+Δ1+0)+(float)Math.pow(β1*ts,4)/12/1000000000/1000);
        X = 2*ω*0.0000001f*(float)Math.log(2*dlcf.getCdaxis()/(Ds+ts));
        λ11 = Rs/Rc/(1+(Rs/X*Rs/X));
        if(dlcf.getCablegroundmethod()==1)
        {
            λ1=0+λ12;            
        }
        else if(dlcf.getCablegroundmethod()==2)
        {
           λ1=λ11+0;            
        }
        else
            λ1=λ11+λ12;
            //λ1 = 0.9739f;
        Ra = dlcf.getArmorres()*(1+dlcf.getArmorrtempercoef()*(record.getLastcdtemperature()-20));
        if(dlcf.getArmortype()==1)
        λ2=1.23f*Ra/Rc*(2*dlcf.getCdaxis2center()/dlcf.getArmorrad() )*(2*dlcf.getCdaxis2center()/dlcf.getArmorrad() )*1/(1+(2.77f*Ra*1000000/ω)*(2.77f*Ra*1000000/ω));  
        else
        {
            λ2=0;
        }
        float Outlrcoef = dlcf.getOutlrcoef();
        float Outlthick= dlcf.getOutlthick();
        float Cableoutd = dlcf.getCableoutd();

        T1=Outlrcoef/2/3.14159f*(float)Math.log(1+2*ts/Cddter);
        
        if(dlcf.getArmortype()==1)
        T2=dlcf.getInnerrcoef()/2/3.14159f*(float)Math.log(1+2*(dlcf.getInneroutd()-dlcf.getInnerrad())/dlcf.getInneroutd());        
        else
        T2=0;  

        if(dlcf.getArmortype()==1)
            T3= Outlrcoef/2/3.14159f*(float)Math.log(1+2*(Outlthick/(dlcf.getArmorrad()+dlcf.getArmorthick())));          
        else
            T3= Outlrcoef/2/3.14159f*(float)Math.log(1+Outlthick/(Cableoutd+Outlthick));

        float Cable2groundsurf =  dlcf.getCable2groundsurf();
        u= 2*Cable2groundsurf/Cableoutd;
        if(dlcf.getCablelaymethod()==1)
            //T4=100/3.14159f/Cableoutd/8*1000;//h`7~10
            T4=1/3.14159f/Cableoutd/8/(float)Math.pow(90-20,0.25)*1000;
        else if(dlcf.getCablelaymethod()==2) 
        T4=dlcf.getSoilrescoef()/2/3.14159f*(float)Math.log(u + (float)Math.sqrt(u*u-1));
        else if(dlcf.getCablelaymethod()==3) 
        T4=dlcf.getSoilrescoef()/2/3.14159f*((float)Math.log(u + (float)Math.sqrt(u*u-1)) +(float)Math.log(1+2*Cable2groundsurf/dlcf.getCdaxis()*2*Cable2groundsurf/dlcf.getCdaxis()) ); 
        else
        T4=1/3.14159f/Cableoutd/8/(float)Math.pow(90-20,0.25)*1000;
           // T4 = 0.3f;
        //n=1单芯，n=3三芯
        if(dlcf.getCdcorenum()==1)
            calsum = (float)Math.sqrt(((record.getLastcdtemperature()-25)-Wd*(0.5*T1+T2+T3+T4))/(Rc*T1+Rc*(1+λ1)*T2+Rc*(1+λ1+λ2)*(T3+T4)));
        else
            calsum = (float)Math.sqrt(((record.getLastcdtemperature()-25)-Wd*(0.5*T1+3*(T2+T3+T4)))/(Rc*T1+3*Rc*(1+λ1)*T2+3*Rc*(1+λ1+λ2)*(T3+T4)));
            //float a = (90-20)-0.937f*(0.5f*0.3195f+(0.0174f+1.2891f));
            //float b =0.0000108f*0.3195f+0.0000108f*(1+0.9739f)*(0.0174f+1.2891f);
            //calsum = (float)Math.sqrt(a/b);//1480

           if(Float.isNaN(calsum)) 
           {
                calsum=1;
           }


        return calsum;
    }

    public float Calccurrent2(Dlzllsensor record)
    {
        float calsum=0;
        float dcurrent = 1553.6070f;
        float θc =90.0f;
        float a20 = 0f;
        float Wd=0,c=0;
        float ω= 2*3.14159f*50;
        float θs = 0;
        float θc1 =0;
        float λ1=0,λ11=0,λ12=0,Rs=0,gs=0,β1=0,λ0=0,m=0,Δ1=0,X=0;
        float λ2=0,Ra=0;
        float Rc=0, R1p=0, Xs2=0, Ys=0, Xp2=0, Yp=0;
        float T1=0;
        float T3=0;
        float T4=0,u=0;
        float ts=0,Ds=0;
        float As=0;
        Dlzllconfig dlcf = new Dlzllconfig();
        //oc.setStationid(record.getStationid());
        //oc.setDevicegroup(record.getDevicegroup());
        //oc.setDeviceaddr(record.getDeviceaddr());
        Example example = new Example(Dlzllconfig.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stationid", record.getStationid());
        criteria.andEqualTo("devicegroup", record.getDevicegroup());
        criteria.andEqualTo("deviceaddr", record.getDeviceaddr());
        criteria.andEqualTo("pointaddr", record.getPointaddr());
        dlcf = dlzllconfigmapper.selectOneByExample(example);
        float Cddter = dlcf.getCddter();
        //if(dlcf.getArmortype()==1)
        a20 = dlcf.getArmorrtempercoef();
       // else
        //a20 = 0;
        dcurrent = record.getLastdlhlcurrent();
        float R0 = dlcf.getCd20dcr();

        θs = record.getLastskintemperature();
        float R =R0*(1+a20*(θs-20))*0.001f;
        c = dlcf.getInsulε()/18/((float)Math.log(dlcf.getInsuldter())-(float)Math.log(Cddter));
        Wd = ω*c*dlcf.getVollevel()*dlcf.getVollevel()*dlcf.getInsultanδ()*1000000*0.000000001f;
        R1p = dlcf.getCd20dcr()*(1+dlcf.getCdrtempcoef()*(90-20));
        Xs2 = 8*3.14159f*50/R1p*0.0000001f*dlcf.getCdks()*1000;
        Ys = Xs2*Xs2/(192+0.8f*Xs2*Xs2);
        Xp2 = 8*3.14159f*50/R1p*dlcf.getCdkp()*0.0000001f;
        Yp = Xp2*Xp2/(192+0.8f*Xp2*Xp2)*(Cddter/dlcf.getCdaxis())*(Cddter/dlcf.getCdaxis())*(0.312f*(Cddter/dlcf.getCdaxis())*(Cddter/dlcf.getCdaxis())+1.18f/(Xp2*Xp2/(192+0.8f*Xp2*Xp2))+0.27f);
        if(dlcf.getCdcorenum()==1)
        Yp=0;
        Rc = R1p*(1+Ys+Yp)*0.001f;

        ts = dlcf.getMetalthick();
        Ds = dlcf.getMetalinnerd();
       // As = (3.14159f*(Ds+ts)/2*(Ds+ts)/2)*0.000001f;
        As = 3.14159f*Ds*ts*0.000001f;
        β1 = (float)Math.sqrt(4*3.14159f*ω/10000000/dlcf.getMetalres());//2*3.14159f*(2*50/(dlcf.getMetalres()*0.1f);(dlcf.getMetalinnerd()+dlcf.getMetalinnerd()+dlcf.getMetalthick())/2
        gs = 1+(float)Math.pow((ts/(Ds+ts)),1.74f)*(β1*(Ds+ts)*0.001f-1.6f);
        m = ω/(Rc*dlcf.getCdaxis())*0.0000001f;
        λ0 = 6*(m*m)/(1+m*m)*((Ds+ts)/2/dlcf.getCdaxis())*((Ds+ts)/2/dlcf.getCdaxis());
        Δ1 = 0.86f*(float)Math.pow(m,3.08f)*(float)Math.pow((Ds+ts)/2/dlcf.getCdaxis(),1.4f*m+0.7f);
        λ12 =Rs/Rc*(gs*λ0*(1+Δ1+0)+(float)Math.pow(β1*ts,4)/12/1000000000/1000);
        X = 2*ω*0.0000001f*(float)Math.log(2*dlcf.getCdaxis()/(Ds+ts));
        λ11 = Rs/Rc/(1+(Rs/X*Rs/X));
        if(dlcf.getCablegroundmethod()==1)
        {
            λ1=0+λ12;            
        }
        else if(dlcf.getCablegroundmethod()==2)
        {
           λ1=λ11+0;            
        }
        else
            λ1=λ11+λ12;
        float Outlrcoef = dlcf.getOutlrcoef();
        float Outlthick= dlcf.getOutlthick();
        float Cableoutd = dlcf.getCableoutd();
       // T1=dlcf.getOutlrcoef()/2/3.14159f*(float)Math.log(1+2*dlcf.getOutlthick()/dlcf.getCableoutd());
       T1=Outlrcoef/2/3.14159f*(float)Math.log(1+2*ts/Cddter);
       if(dlcf.getArmortype()==1)
        T3= Outlrcoef/2/3.14159f*(float)Math.log(1+2*(Outlthick/(dlcf.getArmorrad()+dlcf.getArmorthick())));          
        else
            T3= Outlrcoef/2/3.14159f*(float)Math.log(1+Outlthick/(Cableoutd+Outlthick));
        float Cable2groundsurf =  dlcf.getCable2groundsurf();
        u= 2*Cable2groundsurf/dlcf.getCableoutd();
        if(dlcf.getCablelaymethod()==1)
            //T4=100/3.14159f/Cableoutd/8*1000;//h`7~10
            T4=1/3.14159f/Cableoutd/8/(float)Math.pow(θs-20,0.25)*1000;
        else if(dlcf.getCablelaymethod()==2)  
        T4=dlcf.getSoilrescoef()/2/3.14159f*(float)Math.log(u + (float)Math.sqrt(u*u-1));
        else if(dlcf.getCablelaymethod()==3) 
        T4=dlcf.getSoilrescoef()/2/3.14159f*((float)Math.log(u + (float)Math.sqrt(u*u-1)) +(float)Math.log(1+2*Cable2groundsurf/dlcf.getCdaxis()*2*Cable2groundsurf/dlcf.getCdaxis()) ); 
        else
        T4=1/3.14159f/Cableoutd/8/(float)Math.pow(θs-20,0.25)*1000;
           // T4 = 1.2f;
        //θc1 = (dcurrent*dcurrent*R+1/2*Wd)*T1+(dcurrent*dcurrent*R*(1+λ1)+Wd)*T3+(dcurrent*dcurrent*R*(1+λ1+λ2)+Wd)*T4 +θs;
        θc1 = (dcurrent*dcurrent*R+1/2*Wd)*T1+(dcurrent*dcurrent*R*(1+λ1)+Wd)*T3 +θs;
         do{
            θc = θc1; 
            if(θc>120) 
            θc = 120;

            R =R0*(1+a20*(θc-20))*0.001f;
            Rs = dlcf.getMetalres()/As*(1+dlcf.getCdrtempcoef()*(θc*0.8f - 20));

            β1 = (float)Math.sqrt(4*3.14159f*ω/10000000/dlcf.getMetalres());//2*3.14159f*(2*50/(dlcf.getMetalres()*0.1f);(dlcf.getMetalinnerd()+dlcf.getMetalinnerd()+dlcf.getMetalthick())/2
            gs = 1+(float)Math.pow((ts/(Ds+ts)),1.74f)*(β1*(Ds+ts)*0.001f-1.6f);
            m = ω/(Rc*dlcf.getCdaxis())*0.0000001f;
            λ0 = 6*(m*m)/(1+m*m)*((Ds+ts)/2/dlcf.getCdaxis())*((Ds+ts)/2/dlcf.getCdaxis());
            Δ1 = 0.86f*(float)Math.pow(m,3.08f)*(float)Math.pow((Ds+ts)/2/dlcf.getCdaxis(),1.4f*m+0.7f);
            λ12 =Rs/Rc*(gs*λ0*(1+Δ1+0)+(float)Math.pow(β1*ts,4)/12/1000000000/1000);
            X = 2*ω*0.0000001f*(float)Math.log(2*dlcf.getCdaxis()/(Ds+ts));
            λ11 = Rs/Rc/(1+(Rs/X*Rs/X));
            if(dlcf.getCablegroundmethod()==1)
            {
                λ1=0+λ12;            
            }
            else if(dlcf.getCablegroundmethod()==2)
            {
               λ1=λ11+0;            
            }
            else
                λ1=λ11+λ12;
            //Ra = dlcf.getArmorres()*(1+dlcf.getArmorrtempercoef()*(record.getLastcdtemperature()-20));
            Ra = dlcf.getArmorres()*(1+dlcf.getArmorrtempercoef()*(θc-20));
            if(dlcf.getArmortype()==1)
                λ2=1.23f*Ra/Rc*(2*dlcf.getCdaxis2center()/dlcf.getArmorrad() )*(2*dlcf.getCdaxis2center()/dlcf.getArmorrad() )*1/(1+(2.77f*Ra*1000000/ω)*(2.77f*Ra*1000000/ω));    
            else
            {
                λ2=0;        
            }
                     
            //θc1 = (dcurrent*dcurrent*R+1/2*Wd)*T1+(dcurrent*dcurrent*R*(1+λ1)+Wd)*T3 +(dcurrent*dcurrent*R*(1+λ1+λ2)+Wd)*T4 +θs;
            θc1 = (dcurrent*dcurrent*R+1/2*Wd)*T1+(dcurrent*dcurrent*R*(1+λ1)+Wd)*T3  +θs;
            if(θc1>120) 
            θc1 = 120;
         }while(Math.abs(θc1-θc)>0.1);
        if(Float.isInfinite(θc))   
        θc=120;
        return θc;
    }

    public float Calccurrentθc(Dlzllsensor record)
    {
        float t=1;
        float τ =0;
        float scurrent = 1553.6070f,dcurrent = 1553.6070f,startdcurrent = 400;
        float θc =40.0f;
        float Q=0,Qa =0,Qb =0,Qb1 =0,Qc=0,Qi=0,Qs=0,Qw=0;
        float p=0,p1=0;
        float e = (float)Math.E;
        float Wd=0,c=0;
        //float δ = 3.45f*1000000,δpe = 2.4f*1000000,δal = 2.5f*1000000;
        float δ = 3.45f,δpe = 2.4f,δal = 2.5f;
        float ω= 2*3.14159f*50;
        float θ0 =0;
        float Di =0;
        float dc =0;
        float De =0;
        float ts=0,Ds=0;
        float As=0;
        float qs=0;
        float Ws=0,Wc=0;
       // float λ1=0,λ11=0,λ12=0,Rs=0,gs=0,β1=0,λ0=0,m=0,Δ1=0,X=0;
       // float λ2=0,Ra=0;
        float Rc=0,Rc0=0, R1p=0, R1p0=0,Xs2=0, Ys=0, Xp2=0, Yp=0;
        float T=0;
        float T1=0;
        float T3=0;
        float T4=0,u=0;
        float Rs=0;
       
        Dlzllconfig dlcf = new Dlzllconfig();
        //oc.setStationid(record.getStationid());
        //oc.setDevicegroup(record.getDevicegroup());
        //oc.setDeviceaddr(record.getDeviceaddr());
        Example example = new Example(Dlzllconfig.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("stationid", record.getStationid());
        criteria.andEqualTo("devicegroup", record.getDevicegroup());
        criteria.andEqualTo("deviceaddr", record.getDeviceaddr());
        criteria.andEqualTo("pointaddr", record.getPointaddr());
        dlcf = dlzllconfigmapper.selectOneByExample(example);
       // a20 = dlcf.getArmorrtempercoef();
       dcurrent = record.getLastdlhlcurrent();
       startdcurrent = record.getLaststartcurrent();//应急负荷
       // float R0 = dlcf.getCd20dcr();
        //float R =R0*(1+a20*(θc-20))*0.001f;
        θ0 = record.getLaststarttemperature();
        t = record.getLastspantime();
        dc = dlcf.getCddter();
        c = dlcf.getInsulε()/18/((float)Math.log(dlcf.getInsuldter())-(float)Math.log(dc))*0.000000001f;
        Wd = ω*c*dlcf.getVollevel()*dlcf.getVollevel()*dlcf.getInsultanδ()*1000000;
        R1p = dlcf.getCd20dcr()*(1+dlcf.getCdrtempcoef()*(90-20));
        R1p0 = dlcf.getCd20dcr()*(1+dlcf.getCdrtempcoef()*(θ0-20));
        Xs2 = 8*3.14159f*50/R1p*0.0000001f*dlcf.getCdks()*1000;
        Ys = Xs2*Xs2/(192+0.8f*Xs2*Xs2);
        Xp2 = 8*3.14159f*50/R1p*dlcf.getCdkp()*0.0000001f;
        Yp = Xp2*Xp2/(192+0.8f*Xp2*Xp2)*(dc/dlcf.getCdaxis())*(dc/dlcf.getCdaxis())*(0.312f*(dc/dlcf.getCdaxis())*(dc/dlcf.getCdaxis())+1.18f/(Xp2*Xp2/(192+0.8f*Xp2*Xp2))+0.27f);
        if(dlcf.getCdcorenum()==1)
        Yp=0;

        Rc = R1p*(1+Ys+Yp)*0.001f;
        Xs2 = 8*3.14159f*50/R1p0*0.0000001f*dlcf.getCdks()*1000;
        Ys = Xs2*Xs2/(192+0.8f*Xs2*Xs2);
        Xp2 = 8*3.14159f*50/R1p0*dlcf.getCdkp()*0.0000001f;
        Yp = Xp2*Xp2/(192+0.8f*Xp2*Xp2)*(dc/dlcf.getCdaxis())*(dc/dlcf.getCdaxis())*(0.312f*(dc/dlcf.getCdaxis())*(dc/dlcf.getCdaxis())+1.18f/(Xp2*Xp2/(192+0.8f*Xp2*Xp2))+0.27f);
        if(dlcf.getCdcorenum()==1)
        Yp=0;
        Rc0 = R1p0*(1+Ys+Yp)*0.001f;
        ts = dlcf.getMetalthick();
        Ds = dlcf.getMetalinnerd();
        //Rs = dlcf.getMetalres()/(3.14159f*(dlcf.getMetalinnerd()+dlcf.getMetalthick())/2*(dlcf.getMetalinnerd()+dlcf.getMetalthick())/2)*(1+dlcf.getCdrtempcoef()*(record.getLastcdtemperature()*0.8f - 20));
        As = 3.14159f*Ds*ts*0.000001f;
        Rs = dlcf.getMetalres()/As*(1+dlcf.getCdrtempcoef()*(record.getLastcdtemperature()*0.8f - 20));
        // β1 = (float)Math.sqrt(4*3.14159f*ω/10000000/dlcf.getMetalres());//2*3.14159f*(2*50/(dlcf.getMetalres()*0.1f);(dlcf.getMetalinnerd()+dlcf.getMetalinnerd()+dlcf.getMetalthick())/2
        // gs = 1+(float)Math.pow((dlcf.getMetalthick()/(dlcf.getMetalinnerd()+dlcf.getMetalthick())),1.74f)*(β1*(dlcf.getMetalinnerd()+dlcf.getMetalthick())*0.001f-1.6f);
        // m = ω/(Rc*dlcf.getCdaxis())*0.0000001f;
        // λ0 = 6*(m*m)/(1+m*m)*((dlcf.getMetalinnerd()+dlcf.getMetalthick())/2/dlcf.getCdaxis())*((dlcf.getMetalinnerd()+dlcf.getMetalthick())/2/dlcf.getCdaxis());
        // Δ1 = 0.86f*(float)Math.pow(m,3.08f)*(float)Math.pow((dlcf.getMetalinnerd()+dlcf.getMetalthick())/2/dlcf.getCdaxis(),1.4f*m+0.7f);
        // λ12 =Rs/Rc*(gs*λ0*(1+Δ1+0)+(float)Math.pow(β1*dlcf.getMetalthick(),4)/12/1000000000/1000);
        // X = 2*ω*0.0000001f*(float)Math.log(2*dlcf.getCdaxis()/(dlcf.getMetalinnerd()+dlcf.getMetalthick()));
        // λ11 = Rs/Rc/(1+(Rs/X*Rs/X));
        // if(dlcf.getCablegroundmethod()==1)
        // {
        //     λ1=0+λ12;            
        // }
        // else if(dlcf.getCablegroundmethod()==2)
        // {
        //    λ1=λ11+0;            
        // }
        // else
        //     λ1=λ11+λ12;
        // //Ra = dlcf.getArmorres()*(1+dlcf.getArmorrtempercoef()*(record.getLastcdtemperature()-20));
        // Ra = dlcf.getArmorres()*(1+dlcf.getArmorrtempercoef()*(θc-20));
        // if(dlcf.getArmortype()==1)
        //     λ2=0;
        // else
        // {
        //     λ2=1.23f*Ra/Rc*(2*dlcf.getCdaxis2center()/dlcf.getArmorrad() )*(2*dlcf.getCdaxis2center()/dlcf.getArmorrad() )*1/(1+(2.77f*Ra*1000000/ω)*(2.77f*Ra*1000000/ω));            
        // }
        float Outlrcoef = dlcf.getOutlrcoef();
        float Outlthick= dlcf.getOutlthick();
        float Cableoutd = dlcf.getCableoutd();
        T1=Outlrcoef/2/3.14159f*(float)Math.log(1+2*ts/dc);
        if(dlcf.getArmortype()==1)
            T3= Outlrcoef/2/3.14159f*(float)Math.log(1+2*(Outlthick/(dlcf.getArmorrad()+dlcf.getArmorthick())));          
        else
            T3= Outlrcoef/2/3.14159f*(float)Math.log(1+Outlthick/(Cableoutd+Outlthick));
        float Cable2groundsurf =  dlcf.getCable2groundsurf();
        u= 2*Cable2groundsurf/dlcf.getCableoutd();
        if(dlcf.getCablelaymethod()==1)
            //T4=100/3.14159f/Cableoutd/8*1000;//h`7~10
            T4=1/3.14159f/Cableoutd/8/(float)Math.pow(record.getLastskintemperature()-20,0.25)*1000;
        else if(dlcf.getCablelaymethod()==2)  
        T4=dlcf.getSoilrescoef()/2/3.14159f*(float)Math.log(u + (float)Math.sqrt(u*u-1));
        else if(dlcf.getCablelaymethod()==3) 
        T4=dlcf.getSoilrescoef()/2/3.14159f*((float)Math.log(u + (float)Math.sqrt(u*u-1)) +(float)Math.log(1+2*Cable2groundsurf/dlcf.getCdaxis()*2*Cable2groundsurf/dlcf.getCdaxis()) ); 
        else
        T4=1/3.14159f/Cableoutd/8/(float)Math.pow(record.getLastskintemperature()-20,0.25)*1000;

        Di =dlcf.getInsuldter();
        
        //De-Ds = dlcf.getOutlthick();
        De = dlcf.getCableoutd();
        Ds = De - dlcf.getOutlthick();

        T = T1+T3 +T4;
        Qc = δ*3.14159f/4*dc*(Di-dc);
        Qi = δpe*3.14159f/4*Di*(Di-dc);
        Qs = δal*3.14159f/4*Ds*dlcf.getOutlthick();
        Qw = δal*3.14159f/4*De*dlcf.getOutlthick();
        p=1/(2*(float)Math.log(Di/dc)) - 1/(-1+(Di/dc)*(Di/dc));
        p1=1/(2*(float)Math.log(De/Ds)) - 1/(-1+(De/Ds)*(De/Ds));

        Qa = Qc+p*Qi;
        scurrent = startdcurrent +dcurrent;
        Wc = scurrent*scurrent*Rc;
        if(dlcf.getCablegroundmethod()==1)
            Ws = 0;
        else
            Ws = scurrent*scurrent*Rs; 

        qs = 1+Ws/Wc;
        Qb = (1-p)*Qi + (Qs + p1*Qw)/qs;
        Qb1 = (1-p1)*Qw/qs;

        Q = Qa+Qb+Qb1;
        τ = (T*Q)/3600;
        float wcT = Wc*T- (dcurrent*dcurrent*Rc0*T);
        θc =  θ0 + wcT*(1-(float)Math.pow(e,-t/τ));


        return θc;
    }

    public float CalccurrentT(Dlzllsensor record)
    {
        float t=1;
        float τ =0;
        float scurrent = 1553.6070f,dcurrent = 1553.6070f,startdcurrent = 400;
        float θc =40.0f;
        float Q=0,Qa =0,Qb =0,Qb1 =0,Qc=0,Qi=0,Qs=0,Qw=0;
        float p=0,p1=0;
        float e = 2.72f;
        float Wd=0,c=0;
        //float δ = 3.45f*1000000,δpe = 2.4f*1000000,δal = 2.5f*1000000;
        float δ = 3.45f,δpe = 2.4f,δal = 2.5f;
        float ω= 2*3.14159f*50;
        float θ0 =0;
        float Di =0;
        float dc =0;
        float De =0;
        float ts=0,Ds=0;
        float As=0;
        float qs=0;
        float Ws=0,Wc=0;
       // float λ1=0,λ11=0,λ12=0,Rs=0,gs=0,β1=0,λ0=0,m=0,Δ1=0,X=0;
       // float λ2=0,Ra=0;
        float Rc=0,Rc0=0, R1p=0, R1p0=0, Xs2=0, Ys=0, Xp2=0, Yp=0;
        float T=0;
        float T1=0;
        float T3=0;
        float T4=0,u=0;
        float Rs=0;
        // Dlzllsensor sensor = new Dlzllsensor();
        // Example example = new Example(Dlzllsensor.class);
        // Example.Criteria criteria = example.createCriteria();
        // criteria.andEqualTo("stationid", record.getStationid());
        // criteria.andEqualTo("devicegroup", record.getDevicegroup());
        // criteria.andEqualTo("deviceaddr", record.getDeviceaddr());
        // criteria.andEqualTo("pointaddr", record.getPointaddr());
        // sensor = selectOneByExample(example);

        Dlzllconfig dlcf = new Dlzllconfig();
        //oc.setStationid(record.getStationid());
        //oc.setDevicegroup(record.getDevicegroup());
        //oc.setDeviceaddr(record.getDeviceaddr());
        Example example1 = new Example(Dlzllconfig.class);
        Example.Criteria criteria1 = example1.createCriteria();
        criteria1.andEqualTo("stationid", record.getStationid());
        criteria1.andEqualTo("devicegroup", record.getDevicegroup());
        criteria1.andEqualTo("deviceaddr", record.getDeviceaddr());
        criteria1.andEqualTo("pointaddr", record.getPointaddr());
        dlcf = dlzllconfigmapper.selectOneByExample(example1);
       // a20 = dlcf.getArmorrtempercoef();
        dcurrent = record.getLastdlhlcurrent();
        startdcurrent = record.getLaststartcurrent();//应急负荷
       // float R0 = dlcf.getCd20dcr();
        //float R =R0*(1+a20*(θc-20))*0.001f;
        θ0 = record.getLaststarttemperature();
        //θc = record.getLastcdtemperature();
        //if(θc>90)
        θc = 90;
        //t = sensor.getLastspantime();
        Di =dlcf.getInsuldter();
        dc =dlcf.getCddter();
        //De-Ds = dlcf.getOutlthick();
        De = dlcf.getCableoutd();
        Ds = dlcf.getMetalinnerd()+ dlcf.getMetalthick();

        c = dlcf.getInsulε()/18/((float)Math.log(dlcf.getInsuldter())-(float)Math.log(dc))*0.000000001f;
        Wd = ω*c*dlcf.getVollevel()*dlcf.getVollevel()*dlcf.getInsultanδ()*1000000;
        R1p = dlcf.getCd20dcr()*(1+dlcf.getCdrtempcoef()*(90-20));
        R1p0 = dlcf.getCd20dcr()*(1+dlcf.getCdrtempcoef()*(θ0-20));
        Xs2 = 8*3.14159f*50/R1p*0.0000001f*dlcf.getCdks()*1000;
        Ys = Xs2*Xs2/(192+0.8f*Xs2*Xs2);
        Xp2 = 8*3.14159f*50/R1p*dlcf.getCdkp()*0.0000001f;
        Yp = Xp2*Xp2/(192+0.8f*Xp2*Xp2)*(dc/dlcf.getCdaxis())*(dc/dlcf.getCdaxis())*(0.312f*(dc/dlcf.getCdaxis())*(dc/dlcf.getCdaxis())+1.18f/(Xp2*Xp2/(192+0.8f*Xp2*Xp2))+0.27f);
        if(dlcf.getCdcorenum()==1)
        Yp=0;
        Rc = R1p*(1+Ys+Yp)*0.001f;

        Xs2 = 8*3.14159f*50/R1p0*0.0000001f*dlcf.getCdks()*1000;
        Ys = Xs2*Xs2/(192+0.8f*Xs2*Xs2);
        Xp2 = 8*3.14159f*50/R1p0*dlcf.getCdkp()*0.0000001f;
        Yp = Xp2*Xp2/(192+0.8f*Xp2*Xp2)*(dc/dlcf.getCdaxis())*(dc/dlcf.getCdaxis())*(0.312f*(dc/dlcf.getCdaxis())*(dc/dlcf.getCdaxis())+1.18f/(Xp2*Xp2/(192+0.8f*Xp2*Xp2))+0.27f);
        if(dlcf.getCdcorenum()==1)
        Yp=0;
        Rc0 = R1p0*(1+Ys+Yp)*0.001f;

        ts = dlcf.getMetalthick();
        //Ds = dlcf.getMetalinnerd();
       // Rs = dlcf.getMetalres()/(3.14159f*(dlcf.getMetalinnerd()+dlcf.getMetalthick())/2*(dlcf.getMetalinnerd()+dlcf.getMetalthick())/2)*(1+dlcf.getCdrtempcoef()*(record.getLastcdtemperature()*0.8f - 20));
       As = 3.14159f*Ds*ts*0.000001f;
       Rs = dlcf.getMetalres()/As*(1+dlcf.getCdrtempcoef()*(θc*0.8f - 20));
        // β1 = (float)Math.sqrt(4*3.14159f*ω/10000000/dlcf.getMetalres());//2*3.14159f*(2*50/(dlcf.getMetalres()*0.1f);(dlcf.getMetalinnerd()+dlcf.getMetalinnerd()+dlcf.getMetalthick())/2
        // gs = 1+(float)Math.pow((dlcf.getMetalthick()/(dlcf.getMetalinnerd()+dlcf.getMetalthick())),1.74f)*(β1*(dlcf.getMetalinnerd()+dlcf.getMetalthick())*0.001f-1.6f);
        // m = ω/(Rc*dlcf.getCdaxis())*0.0000001f;
        // λ0 = 6*(m*m)/(1+m*m)*((dlcf.getMetalinnerd()+dlcf.getMetalthick())/2/dlcf.getCdaxis())*((dlcf.getMetalinnerd()+dlcf.getMetalthick())/2/dlcf.getCdaxis());
        // Δ1 = 0.86f*(float)Math.pow(m,3.08f)*(float)Math.pow((dlcf.getMetalinnerd()+dlcf.getMetalthick())/2/dlcf.getCdaxis(),1.4f*m+0.7f);
        // λ12 =Rs/Rc*(gs*λ0*(1+Δ1+0)+(float)Math.pow(β1*dlcf.getMetalthick(),4)/12/1000000000/1000);
        // X = 2*ω*0.0000001f*(float)Math.log(2*dlcf.getCdaxis()/(dlcf.getMetalinnerd()+dlcf.getMetalthick()));
        // λ11 = Rs/Rc/(1+(Rs/X*Rs/X));
        // if(dlcf.getCablegroundmethod()==1)
        // {
        //     λ1=0+λ12;            
        // }
        // else if(dlcf.getCablegroundmethod()==2)
        // {
        //    λ1=λ11+0;            
        // }
        // else
        //     λ1=λ11+λ12;
        // //Ra = dlcf.getArmorres()*(1+dlcf.getArmorrtempercoef()*(record.getLastcdtemperature()-20));
        // Ra = dlcf.getArmorres()*(1+dlcf.getArmorrtempercoef()*(θc-20));
        // if(dlcf.getArmortype()==1)
        //     λ2=0;
        // else
        // {
        //     λ2=1.23f*Ra/Rc*(2*dlcf.getCdaxis2center()/dlcf.getArmorrad() )*(2*dlcf.getCdaxis2center()/dlcf.getArmorrad() )*1/(1+(2.77f*Ra*1000000/ω)*(2.77f*Ra*1000000/ω));            
        // }
        float Outlrcoef = dlcf.getOutlrcoef();
        float Outlthick= dlcf.getOutlthick();
        float Cableoutd = dlcf.getCableoutd();
        T1=Outlrcoef/2/3.14159f*(float)Math.log(1+2*ts/dc);
        if(dlcf.getArmortype()==1)
            T3= Outlrcoef/2/3.14159f*(float)Math.log(1+2*(Outlthick/(dlcf.getArmorrad()+dlcf.getArmorthick())));          
        else
            T3= Outlrcoef/2/3.14159f*(float)Math.log(1+Outlthick/(Cableoutd+Outlthick));
        float Cable2groundsurf =  dlcf.getCable2groundsurf();    
        u= 2*Cable2groundsurf/dlcf.getCableoutd();
        if(dlcf.getCablelaymethod()==1)
            //T4=100/3.14159f/Cableoutd/9*1000;//h`7~10
            T4=1/3.14159f/Cableoutd/8/(float)Math.pow(record.getLastskintemperature()-20,0.25)*1000;
        else if(dlcf.getCablelaymethod()==2)  
        T4=dlcf.getSoilrescoef()/2/3.14159f*(float)Math.log(u + (float)Math.sqrt(u*u-1));
        else if(dlcf.getCablelaymethod()==3) 
        T4=dlcf.getSoilrescoef()/2/3.14159f*((float)Math.log(u + (float)Math.sqrt(u*u-1)) +(float)Math.log(1+2*Cable2groundsurf/dlcf.getCdaxis()*2*Cable2groundsurf/dlcf.getCdaxis()) ); 
        else
        T4=1/3.14159f/Cableoutd/8/(float)Math.pow(record.getLastskintemperature()-20,0.25)*1000;

        T = T1+T3 +T4;

        //T = 1.08f;
        Qc = δ*3.14159f/4*dc*(Di-dc);
        Qi = δpe*3.14159f/4*Di*(Di-dc);
        Qs = δal*3.14159f/4*Ds*dlcf.getOutlthick();
        Qw = δal*3.14159f/4*De*dlcf.getOutlthick();
        p=1/(2*(float)Math.log(Di/dc)) - 1/(-1+(Di/dc)*(Di/dc));
        p1=1/(2*(float)Math.log(De/Ds)) - 1/(-1+(De/Ds)*(De/Ds));

        Qa = Qc+p*Qi;
        scurrent = startdcurrent +dcurrent;
        Wc = scurrent*scurrent*Rc;
        if(dlcf.getCablegroundmethod()==1)
            Ws = 0;
        else
            Ws = scurrent*scurrent*Rs; 

        qs = 1+Ws/Wc;
        Qb = (1-p)*Qi + (Qs + p1*Qw)/qs;
        Qb1 = (1-p1)*Qw/qs;

        Q = Qa+Qb+Qb1;
       // Q = 13682;
        τ = (T*Q)/3600;
       // θc =  θ0 + Wc*T*(1-1/(float)Math.pow(e,t/τ));
       float wcT = Wc*T- (dcurrent*dcurrent*Rc0*T);
       θc = wcT+θ0-1;
       if(θc>90)
       θc=90;
        t = τ*(float)Math.log(1/(1-(θc-θ0)/(wcT)));
        if(Float.isNaN(t)) 
        t = 100;
        return t;
    }


    public int Update(Dlzllconfig record, Boolean byid) {
        if (byid)
            return dlzllconfigmapper.updateByPrimaryKeySelective(record);
        else
            return dlzllconfigmapper.updateByExampleSelective(record,
                    ConditionDispose.defaultDisposeByUpdate(record, record.getClass()));
    }
    // public int Add(Appdevice record) {
    //     int ret = 1;
    //     Example example = new Example(Dlzllsensor.class);
    //     Example.Criteria criteria = example.createCriteria();
    //     criteria.andEqualTo("stationid",record.getStationid());
    //     criteria.andEqualTo("devicegroup",record.getDevicegroup());
    //    // criteria.andEqualTo("deviceaddr",record.getDeviceaddr());
    //     for (int i = record.getAddrmin(); i < record.getAddrmax() + 1; i++) {
    //         Dlzllsensor sensor = new Dlzllsensor();
    //         sensor.setDeviceaddr(i);
    //         sensor.setCablecircuit(i);
    //         sensor.setDevicename("新电缆");
    //         sensor.setPartitionname("通道"+i);
    //         sensor.setPartitionno(i);
    //         sensor.setStationid(record.getStationid());
    //         sensor.setDevicegroup(record.getDevicegroup());
    //         sensor.setLastcommunicationstatus(-1);
    //         sensor.setLastdatatime(new Date());
    //         sensor.setLastalarmlevel(0);
    //         sensor.setLastalarmmessage("");
    //         if(selectOneByExample(example)==null){
    //             if (insertSelective(sensor) == 0) {
    //                 ret = 0;
    //             }
    //         }
    //     }
    //     return ret;
    // }
    public int Add(Dlzllsensor record) {
        int ret = 1;
        // Example example = new Example(Dlzllsensor.class);
        // Example.Criteria criteria = example.createCriteria();
        // criteria.andEqualTo("stationid",record.getStationid());
        // criteria.andEqualTo("devicegroup",record.getDevicegroup());
        // criteria.andEqualTo("deviceaddr",record.getDeviceaddr());
        //Dlzllsensor sensor = new Dlzllsensor();
        //record.setStationid(record.getStationid());
        //record.setDevicegroup(record.getDevicegroup());
        //record.setDeviceaddr(record.getDeviceaddr());
        //record.setPointaddr(record.getPointaddr());
        if (insertSelective(record) == 0) {
            ret = 0;
        }            
        return ret;           
    }
    public int Add(Dlzllconfig record) {
        return dlzllconfigmapper.insertSelective(record);
    }

    public int Delete(Dlzllconfig record) {
        Example example = new Example(Dlzllconfig.class);
        Example.Criteria criteria = example.createCriteria();
        if (record.getStationid() != null) {
            criteria.andEqualTo("stationid", record.getStationid());
        }
        if (record.getDevicegroup() != null) {
            criteria.andEqualTo("devicegroup", record.getDevicegroup());
        }
        if (record.getDeviceaddr() != null) {
            criteria.andEqualTo("deviceaddr", record.getDeviceaddr());
        }
        return dlzllconfigmapper.deleteByExample(example);
    }
        public MyResult<Dlzllconfig> getList(Dlzllconfig record) {
        List<Dlzllconfig> list = dlzllconfigmapper
                .selectByExample(ConditionDispose.defaultDispose(record, record.getClass()));
        MyResult<Dlzllconfig> result = new MyResult<Dlzllconfig>();
        if (list.size() != 0) {
            result.setCode(0);
            result.setMsg("success");
            result.setCount(list != null && !list.isEmpty() ? list.size() : 0);
            result.setData(list);
        } else {
            result.setCode(1);
            result.setMsg("数据为空");
        }
        return result;
    }
    
    public int Update(Dlzlldssensor record, Boolean byid) {
        if (byid)
            return dlzlldsmapper.updateByPrimaryKeySelective(record);
        else
            return dlzlldsmapper.updateByExampleSelective(record,
                    ConditionDispose.defaultDisposeByUpdate(record, record.getClass()));
    }
    public int Add(Dlzlldssensor record) {
        return dlzlldsmapper.insertSelective(record);
    }
    public int Delete(Dlzlldssensor record) {
        Example example = new Example(Dlzlldssensor.class);
        Example.Criteria criteria = example.createCriteria();
        if (record.getStationid() != null) {
            criteria.andEqualTo("stationid", record.getStationid());
        }
        if (record.getDevicegroup() != null) {
            criteria.andEqualTo("devicegroup", record.getDevicegroup());
        }
        if (record.getDeviceaddr() != null) {
            criteria.andEqualTo("deviceaddr", record.getDeviceaddr());
        }
        if (record.getPointaddr() != null) {
            criteria.andEqualTo("pointaddr", record.getPointaddr());
        }
        return dlzlldsmapper.deleteByExample(example);
    }
    /**
     * 查询实时表曲线
     * 
     * @param record
     * @return
     */
    public MyResult<chartres> getCurveList(Dlzlldssensor  record, String lstr) {
        List<String> legend = new ArrayList<>();
        List<String> columns = new ArrayList<>();
        Dlzlldssensor dlds= new Dlzlldssensor();
        Example example1 = new Example(Dlzlldssensor.class);
        Example.Criteria criteria1 = example1.createCriteria();
        criteria1.andEqualTo("stationid", record.getStationid());
        criteria1.andEqualTo("devicegroup", record.getDevicegroup());
        criteria1.andEqualTo("deviceaddr", record.getDeviceaddr());
        criteria1.andEqualTo("pointaddr", record.getPointaddr());
        criteria1.andEqualTo("lastspantime",1);
        dlds = dlzlldsmapper.selectOneByExample(example1);
        if (dlds == null) {
            return new MyResult<chartres>(1, "曲线图查询失败！地址" + record.getDeviceaddr() + "不存在！");
        }
       // BeanUtils.copyProperties(t, table);
        String[] leg = dlds.getStyle().split(",");
        if (lstr == null) {
            for (int i = 0; i < leg.length; i++) {
                if (leg[i].split("\\|")[1].equals("1")) {
                    String[] ls = leg[i].split("\\|");
                    //if (getValueType("last" + ls[0], dlds)) {
                        legend.add(ls[2]);
                        columns.add("last" + ls[0]);
                    //}
                }
            }
        } else {
            String[] lstrs = lstr.split(",");
            for (int i = 0; i < leg.length; i++) {
                for (int j = 0; j < lstrs.length; j++) {
                    if (leg[i].split("\\|")[0].equals(lstrs[j])) {
                        String[] ls = leg[i].split("\\|");
                       // if (getValueType("last" + ls[0], t)) {
                            legend.add(ls[2]);
                            columns.add("last" + ls[0]);
                       // }
                    }
                }
            }
        }
        List<Dlzlldssensor> list = new ArrayList<>();
        //PageHelper.startPage(pageBase.getPage(), pageBase.getLimit());
        Example example = ConditionDispose.defaultDispose(record, record.getClass());
        example.setOrderByClause("lastspantime desc");
        list = dlzlldsmapper.selectByExample(example);
        //if (pageBase.getPagecount() != null) {
           // int list_size = pageBase.getPage() * pageBase.getLimit() - pageBase.getPagecount();
            //if (list_size > 0 && list_size < list.size()) {
                // 删除多余的查询条数
           //     list = list.subList(0, list.size() - list_size);
           // }
       // }
        Collections.reverse(list);
        chartres cts = new chartres();
        cts.setLegend(legend);
        int len = cts.getLegend().size();
        int llen = list.size();
        String[] dt = new String[llen];
        float[][] sres = new float[len][llen];
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM ddHH:mm:ss 'GMT'XXX yyyy", Locale.US);
        SimpleDateFormat csdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        for (int i = 0; i < list.size(); i++) {
            for (int j = 0; j < cts.getLegend().size(); j++) {
                String s = getValue(columns.get(j), list.get(i));
                if (s != null && !s.equals(""))
                    sres[j][i] = Float.parseFloat(s);
            }
            try {
                if (CommPortManager.isnull(getValue("lastdatatime", list.get(i))).contains("CST")) {
                    dt[i] = sdf2.format(csdf.parse(getValue("lastdatatime", list.get(i))));
                } else if (CommPortManager.isnull(getValue("lastdatatime", list.get(i))).contains("GMT")) {
                    dt[i] = sdf2.format(sdf.parse(getValue("lastdatatime", list.get(i))));
                } else {
                    dt[i] = sdf2.format(csdf.parse(getValue("lastdatatime", list.get(i))));
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        cts.setDt(dt);
        for (int j = 0; j < len; j++) {
            String ename = columns.get(j);
            cts.getSerieslist().add(new series(cts.getLegend().get(j), 1,"line", ename,sres[j]));
        }
        List<chartres> chlist = new ArrayList<>();
        chlist.add(cts);
        MyResult<chartres> result = new MyResult<chartres>();
        if (cts.getSerieslist().size() != 0) {
            result.setCode(0);
            result.setMsg("success");
            result.setCount(cts.getSerieslist().size());
            result.setData(chlist);
        } else {
            result.setCode(1);
            result.setMsg("数据为空");
        }
        return result;
    }
     /**
     * 导出实时表Excel
     * 
     * @param record
     * @return
     */
    public Workbook writeToExcelBySensorList(Dlzlldssensor record) {
        List<String> legend = new ArrayList<>();
        List<String> columns = new ArrayList<>();
        // DefaultPropertyByInsert table = new DefaultPropertyByInsert();
        // DefaultProperty table1 = new DefaultProperty();
        // BeanUtils.copyProperties(record, table1);
        // table.setStationid(table1.getStationid());
        // table.setDevicegroup(table1.getDevicegroup());
        // table.setDeviceaddr(table1.getDeviceaddr());
        // table.setPointaddr(table1.getPointaddr());
        // T t = newTclass(modelClass);
        // BeanUtils.copyProperties(table, t);
        // List<T> tlist = getLists(t);
        Dlzlldssensor dlds= new Dlzlldssensor();
        Example example1 = new Example(Dlzlldssensor.class);
        Example.Criteria criteria1 = example1.createCriteria();
        criteria1.andEqualTo("stationid", record.getStationid());
        criteria1.andEqualTo("devicegroup", record.getDevicegroup());
        criteria1.andEqualTo("deviceaddr", record.getDeviceaddr());
        criteria1.andEqualTo("pointaddr", record.getPointaddr());
        criteria1.andEqualTo("lastspantime",1);
        dlds = dlzlldsmapper.selectOneByExample(example1);
        if (dlds == null) {
            //return new MyResult<chartres>(1, "曲线图查询失败！地址" + dlds.getDeviceaddr() + "不存在！");
        }
        // if (list.size() == 0) {
        //     return new XSSFWorkbook();
        // } else {
        //     t = tlist.get(0);
        // }
        //BeanUtils.copyProperties(t, table);
        String[] leg = dlds.getStyle().split(",");
        columns.add("stationid");
        columns.add("devicegroup");
        columns.add("deviceaddr");
        if (dlds.getPointaddr() != null) {
            columns.add("pointaddr");
        }
        columns.add("pointname");
        columns.add("lastdatatime");
        legend.add(languageManager.getLan().getStationID());
        legend.add(languageManager.getLan().getDeviceGroup());
        legend.add(languageManager.getLan().getDeviceAddress());
        if (dlds.getPointaddr() != null) {
            legend.add(languageManager.getLan().getPointAddress());
        }
        legend.add(languageManager.getLan().getPointName());
        legend.add(languageManager.getLan().getDataTime());
        for (int i = 0; i < leg.length; i++) {
            if (leg[i].split("\\|")[1].equals("1")) {
                String[] ls = leg[i].split("\\|");
                //if (getValueType("last" + ls[0], t) || getValueType(ls[0], t)) {
                    legend.add(ls[2]);
                    columns.add("last" + ls[0]);
                    if (ls[0].equals("simxbvoltage")) {

                    }
                //}
            }
        }
        columns.add("lastalarmlevel");
        columns.add("lastalarmmessage");
        legend.add(languageManager.getLan().getAlarmLevel());
        legend.add(languageManager.getLan().getAlarmDetails());
        List<Dlzlldssensor> list = new ArrayList<>();
        Example example = ConditionDispose.defaultDisposeByInUse(record, record.getClass());
        //list = selectByExample(example);
        list = dlzlldsmapper.selectByExample(example);
        // 创建工作薄
        Workbook wb = new XSSFWorkbook();
        // 标题和页码
        CellStyle titleStyle = wb.createCellStyle();
        // 设置单元格对齐方式,水平居左
        titleStyle.setAlignment(HorizontalAlignment.LEFT);
        // 设置字体样式
        Font titleFont = wb.createFont();
        // 字体高度
        titleFont.setFontHeightInPoints((short) 12);
        // 字体样式
        titleFont.setFontName("黑体");
        titleStyle.setFont(titleFont);
        // 创建sheet
        Sheet sheet = wb.createSheet(languageManager.getLan().getRealtimeDetails());
        // 自动设置宽度
        sheet.autoSizeColumn(0);

        // 在sheet中添加标题行// 行数从0开始
        Row row = sheet.createRow((int) 0);
        for (int i = 0; i < legend.size(); i++) {
            if (legend.get(i).equals(languageManager.getLan().getDataTime())) {
                sheet.setColumnWidth(i, 5000);
            }
            Cell cell = row.createCell(i);
            cell.setCellValue(legend.get(i));
            cell.setCellStyle(titleStyle);
        }
        // 数据样式 因为标题和数据样式不同 需要分开设置 不然会覆盖
        CellStyle dataStyle = wb.createCellStyle();
        // 设置居中样式，水平居中
        dataStyle.setAlignment(HorizontalAlignment.CENTER);

        // 数据从序号1开始
        try {
            int index = 1;
            for (Dlzlldssensor value : list) {
                // 默认的行数从0开始，为了统一格式设置从1开始，就是从excel的第二行开始
                row = sheet.createRow(index);
                index++;
                for (int i = 0; i < columns.size(); i++) {
                    Cell cell = row.createCell(i);
                    // 为当前列赋值
                    String val = getValue(columns.get(i), value);
                    if (columns.get(i).equals("status") || columns.get(i).equals("lastcommunicationstatus")) {
                        switch (val) {
                            case "-1":
                                val = languageManager.getLan().getUnknown();
                                break;
                            case "0":
                                val = languageManager.getLan().getRestored();
                                break;
                            case "1":
                                val = languageManager.getLan().getAlarmActive();
                                break;
                            default:
                                break;
                        }
                    }
                    if (columns.get(i).equals("alarmlevel") || columns.get(i).equals("lastalarmlevel")) {
                        switch (val) {
                            case "-1":
                                val = languageManager.getLan().getUnknown();
                                break;
                            case "0":
                                val = languageManager.getLan().getNormal();
                                break;
                            case "1":
                                val = languageManager.getLan().getWarning();
                                break;
                            case "2":
                                val = languageManager.getLan().getAlarm();
                                break;
                            default:
                                break;
                        }
                    }
                    // 断路器机械特性↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                    if (columns.get(i).equals("lastopenorclose")) {
                        switch (val) {
                            case "0":
                                val = "分闸状态";
                                break;
                            case "1":
                                val = "合闸状态";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    if (columns.get(i).equals("laststorage")) {
                        switch (val) {
                            case "0":
                                val = "未储能";
                                break;
                            case "1":
                                val = "已储能";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    if (columns.get(i).equals("lastopeningcircuit")) {
                        switch (val) {
                            case "0":
                                val = "正常";
                                break;
                            case "1":
                                val = "不能合闸";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    if (columns.get(i).equals("lastclosingcircuit")) {
                        switch (val) {
                            case "0":
                                val = "正常";
                                break;
                            case "1":
                                val = "不能分闸";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    // 消弧控制器↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
                    if (columns.get(i).equals("lastascp")) {
                        switch (val) {
                            case "0":
                                val = "分闸";
                                break;
                            case "1":
                                val = "合闸";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    if (columns.get(i).equals("lastbscp")) {
                        switch (val) {
                            case "0":
                                val = "分闸";
                                break;
                            case "1":
                                val = "合闸";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    if (columns.get(i).equals("lastcscp")) {
                        switch (val) {
                            case "0":
                                val = "分闸";
                                break;
                            case "1":
                                val = "合闸";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    if (columns.get(i).equals("lastbusclose")) {
                        switch (val) {
                            case "0":
                                val = "未联机";
                                break;
                            case "1":
                                val = "联机";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    if (columns.get(i).equals("lastisolate")) {
                        switch (val) {
                            case "0":
                                val = "分闸";
                                break;
                            case "1":
                                val = "合闸";
                                break;
                            default:
                                val = "未知";
                                break;
                        }
                    }
                    cell.setCellValue(val);
                    // 设置数据的样式
                    cell.setCellStyle(dataStyle);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return wb;
    }


}
